(function() {

this.codium = this.codium || {};
this.codium.panel = this.codium.panel || {};

this.codium.panel.Overview = codium.panel.BasicPanel.extend(
{
	init : function() 
	{
		this._super();
		
		this.setIcon(this.libDir + "/img/icon/menuOverview.png");
		this.setCaption("Project Overview");
		
		this.service = new codium.CodiumService();
		
		this.pnlMessage = new pasta.webgui.ContainerControl();
		this.pnlMessage.setLeft(10);
		this.pnlMessage.setTop(40);
		this.pnlMessage.setWidth(this.getWidth() - 200);
		this.pnlMessage.setHeight(this.getHeight() - this.pnlMessage.getTop() - this.pnlMessage.getLeft());
		this.pnlMessage.setBorderColor("#FFFFFF");
		this.pnlMessage.setBgColor("#FEFEFE");
		this.pnlMessage.setShadow("0px 2px 4px #000000");
		this.addControl(this.pnlMessage);
		
			this.lblMessageCaption = new pasta.webgui.Label();
			this.lblMessageCaption.setLeft(5);
			this.lblMessageCaption.setTop(5);
			this.lblMessageCaption.setWidth(200);
			this.lblMessageCaption.setCaption("Latest Messages :");
			this.lblMessageCaption.font.setBold(true);
			this.lblMessageCaption.font.setSize(12);
			this.pnlMessage.addControl(this.lblMessageCaption);
			
			this.shpMessageCaption = new pasta.webgui.Shape();
			this.shpMessageCaption.setLeft(this.lblMessageCaption.getLeft());
			this.shpMessageCaption.setTop(this.lblMessageCaption.getTop() + 20);
			this.shpMessageCaption.setWidth(this.pnlMessage.getWidth() - (2 * this.shpMessageCaption.getLeft()));
			this.shpMessageCaption.setMode(2);
			this.pnlMessage.addControl(this.shpMessageCaption);
			
			this.listMessage = new codium.control.MessageList();
			this.listMessage.setLeft(this.shpMessageCaption.getLeft());
			this.listMessage.setTop(this.shpMessageCaption.getTop() + 10);
			this.listMessage.setWidth(this.shpMessageCaption.getWidth());
			this.listMessage.setHeight(this.pnlMessage.getHeight() - this.listMessage.getTop() - 50);
			this.pnlMessage.addControl(this.listMessage);
			
			this.btnNewMessage = new pasta.webgui.Button();
			this.btnNewMessage.setLeft(this.listMessage.getLeft());
			this.btnNewMessage.setTop(this.listMessage.getTop() + this.listMessage.getHeight() + 5);
			this.btnNewMessage.setCaption("New Message");
			this.btnNewMessage.setWidth(95);
			this.btnNewMessage.getOnClick().setHandler(this, this.btnNewMessageClick);
			this.pnlMessage.addControl(this.btnNewMessage);
			
			this.btnRefreshMessage = new pasta.webgui.Button();
			this.btnRefreshMessage.setLeft(this.btnNewMessage.getLeft() + this.btnNewMessage.getWidth() + 3);
			this.btnRefreshMessage.setTop(this.btnNewMessage.getTop());
			this.btnRefreshMessage.setCaption("Refresh");
			this.btnRefreshMessage.setWidth(80);
			this.btnRefreshMessage.getOnClick().setHandler(this, this.btnRefreshMessageClick);
			this.pnlMessage.addControl(this.btnRefreshMessage);
			
		this.pnlMilestone = new pasta.webgui.ContainerControl();
		this.pnlMilestone.setLeft(this.pnlMessage.getLeft() + this.pnlMessage.getWidth() + 10);
		this.pnlMilestone.setTop(this.pnlMessage.getTop());
		this.pnlMilestone.setWidth(this.getWidth() - this.pnlMilestone.getLeft() - this.pnlMessage.getLeft());
		this.pnlMilestone.setHeight(200);
		this.pnlMilestone.setBorderColor("#FFFFFF");
		this.pnlMilestone.setBgColor("#FEFEFE");
		this.pnlMilestone.setShadow("0px 2px 4px #000000");
		this.addControl(this.pnlMilestone);
		
			this.lblMilestoneCaption = new pasta.webgui.Label();
			this.lblMilestoneCaption.setLeft(5);
			this.lblMilestoneCaption.setTop(5);
			this.lblMilestoneCaption.setWidth(200);
			this.lblMilestoneCaption.setCaption("Upcoming Milestones :");
			this.lblMilestoneCaption.font.setBold(true);
			this.lblMilestoneCaption.font.setSize(12);
			this.pnlMilestone.addControl(this.lblMilestoneCaption);
			
			this.shpMilestoneCaption = new pasta.webgui.Shape();
			this.shpMilestoneCaption.setLeft(this.lblMilestoneCaption.getLeft());
			this.shpMilestoneCaption.setTop(this.lblMilestoneCaption.getTop() + 20);
			this.shpMilestoneCaption.setWidth(this.pnlMilestone.getWidth() - (2 * this.shpMilestoneCaption.getLeft()));
			this.shpMilestoneCaption.setMode(2);
			this.pnlMilestone.addControl(this.shpMilestoneCaption);
			
		this.pnlActivities = new pasta.webgui.ContainerControl();
		this.pnlActivities.setLeft(this.pnlMilestone.getLeft());
		this.pnlActivities.setTop(this.pnlMilestone.getTop() + this.pnlMilestone.getHeight() + 10);
		this.pnlActivities.setWidth(this.pnlMilestone.getWidth());
		this.pnlActivities.setHeight(this.getHeight() - this.pnlActivities.getTop() - this.pnlMessage.getLeft());
		this.pnlActivities.setBorderColor("#FFFFFF");
		this.pnlActivities.setBgColor("#FEFEFE");
		this.pnlActivities.setShadow("0px 2px 4px #000000");
		this.addControl(this.pnlActivities);
		
			this.lblActivitiesCaption = new pasta.webgui.Label();
			this.lblActivitiesCaption.setLeft(5);
			this.lblActivitiesCaption.setTop(5);
			this.lblActivitiesCaption.setWidth(200);
			this.lblActivitiesCaption.setCaption("Latest Activities :");
			this.lblActivitiesCaption.font.setBold(true);
			this.lblActivitiesCaption.font.setSize(12);
			this.pnlActivities.addControl(this.lblActivitiesCaption);
			
			this.shpActivitiesCaption = new pasta.webgui.Shape();
			this.shpActivitiesCaption.setLeft(this.lblActivitiesCaption.getLeft());
			this.shpActivitiesCaption.setTop(this.lblActivitiesCaption.getTop() + 20);
			this.shpActivitiesCaption.setWidth(this.pnlActivities.getWidth() - (2 * this.shpActivitiesCaption.getLeft()));
			this.shpActivitiesCaption.setMode(2);
			this.pnlActivities.addControl(this.shpActivitiesCaption);
	},	
	
	initPanel : function()
	{
		this.refreshMessage();
	},
	
	refreshMessage : function()
	{
		var target = this;
		this.service.listMessage(app.projectId, function(result) {target.updateMessage(result);});
	},
	
	updateMessage : function(list)
	{
		this.listMessage.clear();
		
		for (var i = 0; i < list.length; i++)
		{
			var obj = list[i];
			
			this.listMessage.addMessage(obj.messageTitle, obj.messageUserName, obj.messageDate, obj.description);
		}
	},
	
	//-------------------- Event Handler --------------
	
	btnNewMessageClick : function(sender)
	{
		if (this.pnlNewMessage == null)
		{
			this.pnlNewMessage = new codium.panel.NewMessage();
			this.pnlNewMessage.getOnOK().setHandler(this, this.pnlNewMessageOK);
			this.pnlNewMessage.setWidth(stage.getWidth());
			this.pnlNewMessage.setHeight(stage.getHeight());
			stage.addControl(this.pnlNewMessage);
		}
		
		this.pnlNewMessage.show();
	},
	
	btnRefreshMessageClick : function(sender)
	{
		this.refreshMessage();
	},
	
	pnlNewMessageOK : function(sender, title, msg)
	{
		var target = this;
		this.service.addMessage(app.projectId, app.userObj.userId, title, msg, function(result) {target.refreshMessage();});
	},
	
	//-------------------- Setter --------------
	
	setWidth : function(data)
	{
		this._super(data);
		
		if (this.pnlMessage != null)
		{
			this.pnlMessage.setWidth(this.getWidth() - 350);
			
				this.shpMessageCaption.setWidth(this.pnlMessage.getWidth() - (2 * this.shpMessageCaption.getLeft()));
				this.listMessage.setWidth(this.shpMessageCaption.getWidth());
			
			this.pnlMilestone.setLeft(this.pnlMessage.getLeft() + this.pnlMessage.getWidth() + 10);
			this.pnlMilestone.setWidth(this.getWidth() - this.pnlMilestone.getLeft() - this.pnlMessage.getLeft());
			
				this.shpMilestoneCaption.setWidth(this.pnlMilestone.getWidth() - (2 * this.shpMilestoneCaption.getLeft()));
			
			this.pnlActivities.setLeft(this.pnlMilestone.getLeft());
			this.pnlActivities.setWidth(this.pnlMilestone.getWidth());
			
				this.shpActivitiesCaption.setWidth(this.pnlActivities.getWidth() - (2 * this.shpActivitiesCaption.getLeft()));
		}
		
		if (this.pnlNewMessage != null)
			this.pnlNewMessage.setWidth(stage.getWidth());
	},
	
	setHeight : function(data)
	{
		this._super(data);
		
		if (this.pnlMessage != null)
		{
			this.pnlMessage.setHeight(this.getHeight() - this.pnlMessage.getTop() - this.pnlMessage.getLeft());
			
				this.listMessage.setHeight(this.pnlMessage.getHeight() - this.listMessage.getTop() - 50);
				this.btnNewMessage.setTop(this.listMessage.getTop() + this.listMessage.getHeight() + 5);
				this.btnRefreshMessage.setTop(this.btnNewMessage.getTop());
				
			this.pnlActivities.setHeight(this.getHeight() - this.pnlActivities.getTop() - this.pnlMessage.getLeft());
		}
		
		if (this.pnlNewMessage != null)
			this.pnlNewMessage.setHeight(stage.getHeight());
	},
	
});

})();